package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 黑马程序员
 */
public interface ShoppingCartMapper {

    //根据用户的id与菜品id或套餐id查询购物车记录对象
    ShoppingCart findByUidAndDidOrSetmealId(ShoppingCart shoppingCart);

    //插入购物车记录
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);

    //更新份数
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart ShoppingCart);

    @Select("select * from shopping_cart where user_id=#{uid}")
    List<ShoppingCart> findAllByUid(Long uid);

    //根据用户id删除购物车数据
    @Delete("delete from shopping_cart where user_id=#{uid}")
    void clean(Long uid);


    void updateSub(ShoppingCart ShoppingCart);


    ShoppingCart findByDishIdAndUserId(ShoppingCart shoppingCart);


    void deleteSub(ShoppingCart shoppingCart);
}
